"""
generate commands by param
"""
import re

def generate_command(args: dict, process_name: str) -> str:
    """_summary_

    Args:
        args (dict): _description_
        process_name (str): _description_
    command =s:
        str: _description_
    """
    command = ""
    if process_name == "clean":
        if args["program_name"] == "SOAPnuke":
            if args["mode"] == "HPC":
                command = f"""{args["commands"]["SOAPnuke"] if "SOAPnuke" in args["commands"] else "SOAPnuke"} filter \
                {args["options"]} \
                -T {args["cores"]} \
                -1 {args["input_dir"]}/{args["sample_name"]}_1.fq.gz \
                -2 {args["input_dir"]}/{args["sample_name"]}_2.fq.gz \
                -o {args["output_dir"]}/{args["sample_name"]} \
                -C {args["sample_name"]}_1.fq.gz \
                -D {args["sample_name"]}_2.fq.gz
                """
            else:
                command = f"""{args["commands"]["SOAPnuke"] if "SOAPnuke" in args["commands"] else "SOAPnuke"} filter \
                {args["options"]} \
                -T {args["cores"]} \
                -1 {args["input_dir"]}/{args["sample_name"]}_1.fq.gz \
                -2 {args["input_dir"]}/{args["sample_name"]}_2.fq.gz \
                -o {args["output_dir"]} \
                -C {args["sample_name"]}_1.fq.gz \
                -D {args["sample_name"]}_2.fq.gz
                """
        if args["program_name"] == "trim_galore":
            command = f"""{args["commands"]["trim_galore"] if "trim_galore" in args["commands"] else "trim_galore"} \
            {args["options"]} \
            {args["input_dir"]}/{args["sample_name"]}_1.fq.gz \
            {args["input_dir"]}/{args["sample_name"]}_2.fq.gz  \
            -o {args["output_dir"]}/{args["sample_name"]} \
            && mv {args["output_dir"]}/{args["sample_name"]}/* {args["output_dir"]} \
            && rm -r {args["output_dir"]}/{args["sample_name"]} \
            && mv {args["output_dir"]}/{args["sample_name"]}_1_val_1.fq.gz {args["output_dir"]}/{args["sample_name"]}_1.fq.gz \
            && mv {args["output_dir"]}/{args["sample_name"]}_2_val_2.fq.gz {args["output_dir"]}/{args["sample_name"]}_2.fq.gz
            """
    elif process_name == "alignment":
        command = f"""{args["commands"]["hisat2"] if "hisat2" in args["commands"] else "hisat2"} \
        {args["options"]} \
        -p {args["cores"]} \
        -x {args["hisat2_index_directory"]} \
        -1 {args["input_dir"]}/{args["sample_name"]}_1.fq.gz \
        -2 {args["input_dir"]}/{args["sample_name"]}_2.fq.gz | samtools \
        sort -@ {args["cores"]} -O bam -o {args["output_dir"]}/{args["sample_name"]}.bam \
        && samtools index {args["output_dir"]}/{args["sample_name"]}.bam \
	    && samtools flagstat {args["output_dir"]}/{args["sample_name"]}.bam > {args["output_dir"]}/{args["sample_name"]}.stat
        """
    elif process_name == "qualitative":
        if args["program_name"] == "stringtie":
            command = f"""{args["commands"]["stringtie"] if "stringtie" in args["commands"] else "stringtie"} \
            {args["input_dir"]}/{args["sample_name"]}.bam \
            {args["options"]} \
            -p {args["cores"]} \
            -G {args["reference_annotation"]} \
            -A {args["output_dir"]}/{args["sample_name"]}_gene_exp.txt
            """
        if args["program_name"] == "featureCounts":
            command = f"""{args["commands"]["featureCounts"] if "featureCounts" in args["commands"] else "featureCounts"} \
            {args["options"]} \
            -T {args["cores"]} \
            -a {args["reference_annotation"]} \
            -o {args["output_dir"]}/gene_exp.txt \
            {args["input_dir"]}/*.bam
            """

    new_command = re.sub(r"\s+", " ", command)
    return new_command
